#define DEBUG
#include <cstdio>

using namespace std;

const int mods=1000000000, maxn=100000, inf=mods+1;

class Graph {
public:
  int n, m, ind[maxn+1], to[4*maxn+1], link[4*maxn+1], dis[maxn+1];

  void addSide(int u, int v) {
    m++;
    to[m] = v;
    link[m] = ind[u];
    ind[u] = m;
  }

  void calcDis(int s) {
    static bool book[maxn+1];
    static int que[maxn+1];
    for (int i=1; i<=n; i++) {
      dis[i] = inf;
    }
    que[1] = s, dis[s] = 0, book[s] = true;
    for (int h=0, t=1; h!=t; ) {
      int x=que[++h];
      book[x] = false;
      for (int i=ind[x]; i; i=link[i]) {
	if (dis[to[i]]>dis[x]+1) {
	  dis[to[i]] = dis[x]+1;
	  if (!book[to[i]]) {
	    book[to[i]] = true;
	    que[++t] = to[i];
	  }
	}
      }
    }
  }
};

void sort(int a[][2], int l, int r) {
  int i=l, j=r, mid[2]={a[(l+r)/2][0], a[(l+r)/2][1]}, temp;
  for (; i<=j; ) {
    for (; a[j][0]>mid[0] || (a[j][0]==mid[0] && a[j][1]>mid[1]); j--);
    for (; a[i][0]<mid[0] || (a[i][0]==mid[0] && a[i][1]<mid[1]); i++);
    if (i<=j) {
      temp=a[i][0], a[i][0]=a[j][0], a[j][0]=temp;
      temp=a[i][1], a[i][1]=a[j][1], a[j][1]=temp;
      i++, j--;
    }
  }
  if (i<r) {
    sort(a, i, r);
  }
  if (j>l) {
    sort(a, l, j);
  }
}

void connect(Graph *g, int n, int point[][2]) {
  sort(point, 1, n);
  int i=2, j=1;
  for (; point[i][0]==point[j][0]; i++) {
    if (point[i][0]==point[i-1][0] && point[i][1]-1==point[i-1][1]) {
      g->addSide(i, i-1);
      g->addSide(i-1, i);
    }
  }
  for (; i<=n; i++) {
    if (point[i][0]==point[i-1][0] && point[i][1]-1==point[i-1][1]) {
      g->addSide(i, i-1);
      g->addSide(i-1, i);
    }
    for (; point[j][0]<point[i][0]-1 || (point[j][0]==point[i][0]-1 && point[j][1]<point[i][1]); j++);
    if (point[j][0]==point[i][0]-1 && point[j][1]==point[i][1]) {
      g->addSide(j, i);
      g->addSide(i, j);
    }
  }
}

int main() {
  freopen("city.in", "r", stdin);
  freopen("city.out", "w", stdout);

  static Graph g;
  static int point[maxn+1][2];
  int n;
  scanf("%d", &n);
  for (int i=1; i<=n; i++) {
    scanf("%d %d", point[i], point[i]+1);
  }
  g.n = n;
  connect(&g, n, point);

  long long ans=0;
  for (int i=1; i<=n; i++) {
    g.calcDis(i);
    for (int j=i+1; j<=n; j++) {
      ans = (ans+g.dis[j])%mods;
    }
  }
  printf("%lld", ans);

  fclose(stdin);
  fclose(stdout);
  return 0;
}
